﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UDS.Web.UI.Controls
{
    /// <summary>
    /// A special RadioButtonList which just contains 2 items, one for yes, and the other for no.
    /// </summary>
    public class YesNoRadioButtonList : RadioButtonList
    {
        [PersistenceMode(PersistenceMode.Attribute)]
        public bool ChooseYes
        {
            get { return base.SelectedIndex == 0; }
            set { SelectedIndex = value ? 0 : 1; }
        }

        [PersistenceMode(PersistenceMode.Attribute)]
        public string YesText
        {
            get { return Items[0].Text; }
            set { Items[0].Text = value; }
        }

        [PersistenceMode(PersistenceMode.Attribute)]
        public string NoText
        {
            get { return Items[1].Text; }
            set { Items[1].Text = value; }
        }

        /// <summary>
        /// ctor.
        /// </summary>
        public YesNoRadioButtonList()
        {
            Items.Add(new ListItem("Yes", "Yes"));
            Items.Add(new ListItem("No", "No"));

            SelectedIndex = 0;
            RepeatDirection = RepeatDirection.Horizontal;
            RepeatLayout = RepeatLayout.Flow;
        }
    }
}
